package basic.study.leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName Mid17
 * @Description 电话号码的字母组合
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/17 9:45
 * @Version 1.0
 */
public class Mid17 {
    static class Solution {
        List<String> result = new ArrayList<>();
        HashMap<String, String> phone = new HashMap<String, String>() {{
            put("2", "abc");
            put("3", "def");
            put("4", "ghi");
            put("5", "jkl");
            put("6", "mno");
            put("7", "pqrs");
            put("8", "tuv");
            put("9", "wxyz");
        }};

        public List<String> letterCombinations(String digits) {
            if (digits.length() == 0) {
                return result;
            }
            String s = "";
            recall(digits, 0, s);
            return result;
        }

        public void recall(String digits, int index, String s) {
            //如果已经到头
            if (index == digits.length()) {
                result.add(s);
                return;
            }
            String now = String.valueOf(digits.charAt(index));
            char[] numbers = phone.get(now).toCharArray();
            for (char ch: numbers) {
                recall(digits, index+1, s + ch);
            }
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.letterCombinations(""));
    }
}
